package com.alibaba.citrus.cr.price.ability.functions.factory.activity;

import com.alibaba.citrus.cr.price.repository.ActivityQueryRepository;
import com.alibaba.citrus.cr.common.util.SpringContextUtil;
import com.alibaba.citrus.cr.price.ability.functions.entity.activity.ActivityTitleEntity;

import com.epoch.app.crpricecenter.dto.request.ActivityInfoRequest;
import com.epoch.app.crpricecenter.dto.request.ActivityQueryViewRequest;
import com.epoch.app.crpricecenter.sdo.ActivityTitleSDO;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * @author: qiaojiange
 * @create: 2021/10/17
 * @Description 活动抬头工厂
 */
public class ActivityTitleFactory {


    /**
     * 活动查询资源库
     */
    private static ActivityQueryRepository activityQueryRepository = SpringContextUtil.getBean(ActivityQueryRepository.class);
    /**
     * 创建活动抬头实体列表
     * @param request
     * @return
     */
    public static List<ActivityTitleEntity> create(ActivityInfoRequest request) {
        Set<ActivityTitleSDO> activityTitleSDOS = activityQueryRepository.queryActivityTitle(request);
        if(CollectionUtils.isEmpty(activityTitleSDOS)){
            return new ArrayList<>();
        }
        ArrayList<ActivityTitleEntity> result = new ArrayList<>();
        activityTitleSDOS.forEach(sdo -> {
            result.add(ActivityTitleEntity.of(sdo));
        });

        return result;
    }
    /**
     * 创建活动抬头实体
     * @param request
     * @return
     */
    public static ActivityTitleEntity create(ActivityQueryViewRequest request) {

        ActivityTitleSDO activityTitleSDO = new ActivityTitleSDO();
        BeanUtils.copyProperties(request,activityTitleSDO);
        activityTitleSDO.setSalesOrganization(request.getSalesOrganizationId());
        activityTitleSDO.setSalesChannel(request.getChannelId());
        activityTitleSDO.setStart(request.getStart());
        activityTitleSDO.setLimit(request.getLimit());
        ActivityTitleEntity activityTitleEntity = ActivityTitleEntity.of(activityTitleSDO);
        return activityTitleEntity;

    }

    /**
     * 根据活动 id ,查询 activityTitleEntity
     * @param activityId 活动ID
     * @return 返回ActivityTitleEntity
     */
    public static ActivityTitleEntity create(String activityId) {
        ActivityTitleSDO sdo = activityQueryRepository.queryActivityTitleByActivityId(activityId);
        return ActivityTitleEntity.of(sdo);
    }

    /**
     * 根据活动ids查询客户数据
     */
    public static ActivityTitleEntity create(List<String> activityIds){
        return ActivityTitleEntity.of(new ActivityTitleSDO());
    }
}
